//
//  ViewController.m
//  AccessSystemCalendar
//
//  Created by Felix Yin on 2017/3/20.
//  Copyright © 2017年 Felix Yin. All rights reserved.
//

#import "ViewController.h"
//#import "SystemCalendarEvent.h"
//#import "CalendarEventViewModel.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *eventArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource =self;
//    SYSTEM_CALENDAR_EVENT.delegate = self;
    [self.view addSubview:_tableView];
    
    
    UIButton *modifyBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 30, 40)];
    [modifyBtn setTitle:@"修改事件" forState:UIControlStateNormal];
    [self.view addSubview:modifyBtn];
    [modifyBtn addTarget:self action:@selector(modifyEvent) forControlEvents:UIControlEventTouchUpInside];
    
    
    //测试
//    [self testWritingDataToSystemCalendar];
    [self modifyEvent];
//    [self deleteEvent];
    
}



- (void) testWritingDataToSystemCalendar{
   
    NSMutableArray *mArray = [[NSMutableArray alloc] init];
//    CalendarEventViewModel *viewModel = [[CalendarEventViewModel alloc] init];
//    viewModel.eventTitle = @"碰碰日程";
//    viewModel.locationStr = @"北京市故宫";
//    viewModel.eventNotes = @"碰碰日程 升级了！";
//    viewModel.eventStartDate = @"2017-04-11 18:33:00";
//    viewModel.eventEndDate = @"2017-04-11 18:36:00";
//    viewModel.alarmTime = @"-300";
//    [mArray addObject:viewModel];
    
    
//    [SYSTEM_CALENDAR_EVENT saveEventToSystemCalendar:[mArray copy]];

}



- (void) modifyEvent{

    NSMutableArray *mArray = [[NSMutableArray alloc] init];
//    CalendarEventViewModel *viewModel = [[CalendarEventViewModel alloc] init];
//    viewModel.eventTitle = @"碰碰日程";
//    viewModel.locationStr = @"北京市中南海sssKKKKKs";
//    viewModel.eventNotes = @"碰碰日程 升级了！修改";
//    viewModel.eventStartDate = @"2017-04-11 18:55:00";
//    viewModel.eventEndDate = @"2017-04-11 18:59:00";
//    viewModel.alarmTime = @"-120";
//    viewModel.eventID = @"56C0D8FB-63CD-42FD-A159-78C090A92DE1:C6DF4386-D2C0-41DF-A59A-F59A7A85A8D4";
//    [mArray addObject:viewModel];
    
//    [SYSTEM_CALENDAR_EVENT modifyEvent:mArray];

}

- (void) deleteEvent{
//    [SYSTEM_CALENDAR_EVENT removeEvent:@"56C0D8FB-63CD-42FD-A159-78C090A92DE1:C6DF4386-D2C0-41DF-A59A-F59A7A85A8D4"];
}


#pragma mark SystemCalendarEvent Override

- (void)systemCalendarEvent:(SystemCalendarEvent *)calendarEvent events:(NSMutableArray *)events{
    self.eventArray = [events copy];
    [self.tableView reloadData];
}


#pragma mark UITableView Override

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.eventArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellID"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellID"];
    }
//    CalendarEventViewModel *viewModel = [self.eventArray objectAtIndex:indexPath.row];
//    NSString *eventIDSufixx = [viewModel.eventID substringWithRange:NSMakeRange(viewModel.eventID.length - 5, 5)];
//    NSString *eventTitle = viewModel.eventTitle;
//    cell.textLabel.text = [NSString stringWithFormat:@"%@=====%@",eventIDSufixx,eventTitle];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
